package _interview150;

/**
 * 125. 验证回文串
 */
public class No125 {
    public boolean isPalindrome(String s) {
        s = s.toLowerCase();
        int left = 0, right = s.length() - 1;
        while (left < right) {
            if (invalid(s.charAt(left))) {
                left++;
                continue;
            }
            if (invalid(s.charAt(right))) {
                right--;
                continue;
            }
            if (s.charAt(left++) != s.charAt(right--)) return false;
        }
        return true;
    }

    private boolean invalid(char c) {
        return !Character.isDigit(c) && !Character.isLowerCase(c);
    }
}
